using System;
using System.Timers;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace atomtask
{
	[Activity (Label = "@string/appName", MainLauncher = true)]
	public class MainActivity : Activity
	{
		private TextView textLoading;
		private int count;
		private System.Timers.Timer loadingTimer;

		private void init()
		{
			textLoading = FindViewById<TextView> (Resource.Id.txt_Main_Loading);
			count = 0;

			// Create the loading timer
			loadingTimer = new System.Timers.Timer (200);
			loadingTimer.Elapsed += new ElapsedEventHandler (OnTimedEvent);
			loadingTimer.Start ();
		}

		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			// Initialize
			init ();
		}

		private void OnTimedEvent(object source, ElapsedEventArgs e)
		{
			loadingTimer.Stop ();
			RunOnUiThread (()=>{
				textLoading.Text = @"Loading (" + count.ToString() + "/20)";
			});

			++count;
			// Loading completion
			if (count > 19) {
				StartActivity (typeof(OnOffActivity));
				this.Finish ();
			}
			else
				loadingTimer.Start ();
		}
	}
}


